home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / bpl70n12.zip / ARISOURC.ZIP / LSHL.ASM < prev    next >
Assembly Source File  |  1993-02-10  |  2KB  |  61 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 7.0        *
  5. ; *     Longint Shift Left                              *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1992,1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   LSHL
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Publics
  19.  
  20.              PUBLIC  LongShl
  21.  
  22. ;-------------------------------------------------------------------------------
  23. ; LongShl performs a logical left shift on its LONGINT argument, that is, the
  24. ; sign is not preserved and there is no check if the results overflows the
  25. ; LONGINT format. It allows a variable shift count to be used, but masks this
  26. ; off so that the count is in the range 0...31. Counts > 31 are not sensible,
  27. ; since the result would be already zero after the 31st shift.
  28. ;
  29. ; INPUT:     DX:AX     argument
  30. ;            CX        count
  31. ;
  32. ; OUTPUT:    DX:AX     argument SHL count
  33. ;
  34. ; DESTROYS:  AX,CX,DX,Flags
  35. ;-------------------------------------------------------------------------------
  36.  
  37. LongShl      PROC    FAR
  38.              AND     CX, 1FH           ; mask off shift count to 0..31
  39.              CMP     CL, 16            ; 16 shifts or more ?
  40.              JAE     $more_16          ; yes
  41.              MOV     BX, AX            ; duplicate lo-word of number
  42.              SHL     DX, CL            ; shift hi-word of number
  43.              SHL     AX, CL            ; shift lo-word of number
  44.              NEG     CL                ; compute new shift count as
  45.              ADD     CL, 16            ; 16 - old shift count
  46.              SHR     BX, CL            ; get bits shifted out of lo-word
  47.              OR      DX, BX            ; insert them into hi-word
  48. $zero_shr:   RET                       ; done
  49. $more_16:    XCHG    AX, DX            ; shift number
  50.              XOR     AX, AX            ;  by 16 bits
  51.              SUB     CL, 16            ; 16 shifts done
  52.              SHL     DX, CL            ; perform remaining shifts
  53.              RET                       ; done
  54. LongShl      ENDP
  55.  
  56.              ALIGN   4
  57.  
  58. CODE         ENDS
  59.  
  60.              END
  61.